@layout("/common/_container.html",{js:["/assets/modular/recy/product/product.js","/assets/common/libs/rapid-validator/prototype_for_validation.js","/assets/common/libs/rapid-validator/validation_cn.js","/assets/common/libs/rapid-validator/tooltips.js"]}){

<div>
    <form action="" class="layui-form">
        <input type="hidden" id="userId" name="userId" value="${user.id}"/>
        <select name="productId" id="productId" lay-search>
            @for(product in productList){
            <option value="${product.id}">${product.productName}(${product.jifen}积分)</option>
            @}elsefor{
                <option value="">积分不足，暂无可兑换商品</option>
            @}
        </select>
        <button class="layui-btn"  lay-submit>兑换</button>
    </form>
</div>
@}
<script>
    layui.use(["form","jquery","admin"],function(){
        var form = layui.form;
        var $ = layui.jquery;
        var admin = layui.admin;

        form.on("submit",function(){
            if(confirm("兑换商品将扣除相应的积分，是否继续？")){

                $.getJSON(Feng.ctxPath+"/wechatUser/exchangeProduct",{"userId":$("#userId").val(),"productId":$("#productId").val()},function(data){
                   if(data.success){
                       Feng.success("兑换成功!");
                       admin.putTempData('formOk', true);

                       //关掉对话框
                       admin.closeThisDialog();
                   }else{
                       Feng.error("兑换失败，请联系管理员！");
                   }
                });
            }
            return false;
        })
    })
</script>